//
//  LJJClassViewController.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/14.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJClassViewController.h"
#import "SXTClassCollectionView.h"
#import "SXTEffectClassModel.h"
#import "SXTClassCollectionModel.h"
#import "LJJGoodsListViewController.h"

@interface LJJClassViewController ()

@property (strong, nonatomic)   SXTClassCollectionView *classCollection;              /** 分类列表 */

@end

@implementation LJJClassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.classCollection];
    __weak typeof (self) weakSelf = self;
    [_classCollection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self referData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma mark -
#pragma mark - method
- (void)referData{
    
    //推荐品牌
    [self getData:@"appBrandareanew/findBrandareanew.do" param:nil success:^(id responseObject) {
        _classCollection.classicClassArray = [SXTClassCollectionModel mj_objectArrayWithKeyValuesArray:responseObject];
        [_classCollection reloadData];
    } error:^(NSError *error) {
        
    }];
    //经典品牌
    [self getData:@"appBrandarea/asianBrand.do" param:nil success:^(id responseObject) {
        _classCollection.recommendClassArray = [SXTClassCollectionModel mj_objectArrayWithKeyValuesArray:responseObject];
        [_classCollection reloadData];
    } error:^(NSError *error) {
        
    }];
    //功效
    [self getData:@"appBrandareatype/findBrandareatype.do" param:nil success:^(id responseObject) {
        _classCollection.effectArray = [SXTEffectClassModel mj_objectArrayWithKeyValuesArray:responseObject];
        [_classCollection reloadData];
    } error:^( NSError *error) {
        
    }];
    
}
- (SXTClassCollectionView *)classCollection{
    if (!_classCollection) {
        UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
        NSInteger itemWidth = 0;
        if (WIDTH > 400) {
            itemWidth = (WIDTH - 4) / 5;
        }else{
            itemWidth = (WIDTH - 3) / 4;
        }
        flowLayout.itemSize = CGSizeMake(itemWidth, itemWidth);
        flowLayout.minimumLineSpacing = 1;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 1, 0);
        flowLayout.headerReferenceSize = CGSizeMake(0, 35);
        _classCollection = [[SXTClassCollectionView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout];
        _classCollection.backgroundColor = RGB(245, 245, 245, 1);
        __weak typeof (self) weakSelf = self;
        _classCollection.selectCellBlock = ^ (NSDictionary *parameterDic){
            [weakSelf pushToClassListViewController:parameterDic];
        };
        
    }
    return _classCollection;
}

- (void)pushToClassListViewController:(NSDictionary *)parameterDic{
    LJJGoodsListViewController *classList = [[LJJGoodsListViewController alloc]init];
//        classList.idDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:parameterDic[@"URL"],@"URL",parameterDic[@"ShopID"],@"ID",parameterDic[@"Type"],@"keyword", nil];
    [self.navigationController pushViewController:classList animated:YES];
}


#pragma mark -
#pragma mark - lazy method

@end
